<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 墨墨之家
  Date: 2021/11/2
  Time: 21:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@include file="/WEB-INF/common/head.jsp" %>
    <%--引入分页条包--%>
    <link rel="stylesheet" href="css/pagination.css">
    <script type="text/javascript" src="jquery/jquery.pagination.js"></script>
    <script type="text/javascript">
        <%--$(function () {--%>
        <%--    //分页导航条函数--%>
        <%--    initPagination();--%>
        <%--})--%>

        <%--function initPagination() {--%>
        <%--    var pageTotal = ${requestScope.pageInfo.total};--%>
        <%--    var properties = {--%>
        <%--        num_edge_entries: 3,--%>
        <%--        prev_text: "上一页",--%>
        <%--        next_text: "下一页",--%>
        <%--        callback: pageSelectCallBack(),--%>
        <%--        num_display_entries: 5,--%>
        <%--        current_page: ${requestScope.pageInfo.pageNum}-1,--%>
        <%--        items_per_page: 5--%>
        <%--    }--%>

        <%--    $("#pagination").pagination(pageTotal, properties)--%>
        <%--}--%>

        <%--//回调函数 交给别人调用--%>
        <%--function pageSelectCallBack(pageIndex, jQuery) {--%>
        <%--    var pageNum = pageIndex + 1;--%>
        <%--    window.location.href = "admin / to / page.html?pageNum=" + pageNum;--%>
        <%--    return false;--%>
        <%--}--%>
        $(function () {
            // 分页函数
            initPagination();
            $(".removeBtn").click(function () {
                var jQuery = $(this).parent().parent().find("td:eq(3)").text();
                ${sessionScope.loginAdmin.id}
                return confirm("您确定要删除【" + jQuery + "】吗");
            })
        })

        function initPagination() {
            var totalRecord = ${requestScope.pageInfo.total};
            // 声明 Pagination 设置属性的 JSON 对象
            var properties = {
                num_edge_entries: 3, // 边缘页数
                num_display_entries: 5, // 主体页数
                callback: pageSelectCallback, // 用户点击“翻页”按钮之后执行翻页操作的回调函数

                current_page: ${requestScope.pageInfo.pageNum-1}, // 当前页，pageNum 从 1 开始， 必须-1 后才可以赋值

                prev_text: "上一页", next_text: "下一页",
                items_per_page:${requestScope.pageInfo.pageSize},// 每页显示 1 项

            };
            // 调用分页导航条对应的 jQuery 对象的 pagination()方法生成导航条
            $("#pagination").pagination(totalRecord, properties);
        }


        // 点击“上一页”、“下一页”或“数字页码”都会触发翻页动作，从而导致当前函数被调用
        // 翻页过程中执行的回调函数
        // pageIndex 是用户在页面上点击的页码数值
        function pageSelectCallback(pageIndex, jQuery) {
            // pageIndex 是当前页页码的索引，相对于 pageNum 来说，pageIndex 比 pageNum 小 1
            var pageNum = pageIndex + 1;
            // 执行页面跳转也就是实现“翻页”
            window.location.href = "admin/to/page.html?pageNum=" + pageNum + "&keyword=${param.keyword}";
            // 取消当前超链接的默认行为
            return false;
        }
    </script>
</head>
<body>
<%--静态包含--%>
<%@include file="/WEB-INF/common/nav.jsp" %>

<div class="container-fluid">
    <%@include file="/WEB-INF/common/sidebar.jsp" %>

    <div class="row">
        <%--静态包含--%>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form action="admin/to/page.html" class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input name="keyword" class="form-control has-success" type="text"
                                       placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询
                        </button>
                    </form>
                    <button type="button" class="btn btn-danger" style="float:right;margin-left:10px;"><i
                            class=" glyphicon glyphicon-remove"></i> 删除
                    </button>
                    <a class="btn btn-primary" href="admin/add/to/admin.html" style="float:right;"><i
                            class="glyphicon glyphicon-plus"></i>
                        新增</a>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${empty requestScope.pageInfo.list}">
                                <tr>
                                    <td colspan="6" align="center">抱歉，您访问的数据为空</td>
                                </tr>
                            </c:if>
                            <c:forEach items="${requestScope.pageInfo.list}" var="admin" varStatus="i">
                                <tr>
                                    <td>${i.count}</td>
                                    <td><input type="checkbox"></td>
                                    <td>${admin.loginAcct}</td>
                                    <td>${admin.userName}</td>
                                    <td>${admin.email}</td>
                                    <td>
                                            <%--<button type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></button>--%>
                                        <a href="assign/to/role.html?adminId=${admin.id}&pageNum=${pageInfo.pageNum}&keyword=${param.keyword}"
                                           class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></a>
                                        <a class=" btn btn-primary btn-xs" href="admin/id/page.html?id=${admin.id}"><i
                                                class=" glyphicon glyphicon-pencil"></i></a>
                                        <a class="removeBtn"
                                           href="admin/delete/to/admin/${admin.id}/${pageInfo.pageNum}/${param.keyword}.html"
                                           class="btn btn-danger btn-xs"><i
                                                class="glyphicon glyphicon-remove"></i></a>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" align="center">
                                    <%--分页条的位置--%>
                                    <div id="pagination" class="pagination"></div>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>
